package com.java.web;

import com.java.Servive.impl.adminServiceImpl;
import com.java.Servive.userService;
import com.java.dao.userDao;
import com.java.dao.userDaoImpl;
import com.java.doMain.user;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author xyd
 * @Date 2021/12/22 16:54
 * @Version 1.0
 */
public class LoginServlet extends HttpServlet {

    private userDao userDao = new userDaoImpl();

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String username = req.getParameter("username");
        String password = req.getParameter("password");
        user uu = new user();
        uu.setUsername(username);
        uu.setPassword(password);
        user user = userDao.queryAdminByUsernameAndPassword(username, password);
        if (user!=null){
            //session   域对象
            req.getSession().setAttribute("user",user);
            req.getRequestDispatcher(req.getContextPath() + "/client/myAccount.jsp").forward(req,resp);
        }
    }
}
